<?php
/*
 * Copyright notice
 * 
 * (c) 2009 MH-Dev.de, Martin Hesse <info@mh-dev.de>
 * 
 * This script is part of the MH-Dev.-Board project. The MH-Dev.-Board 
 * is free software; you can redistribute it and/or modify it under the 
 * terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, 
 * or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty 
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU 
 * General Public License along with this program; if not, 
 * see http://www.gnu.org/licenses/.
 */


/**
 * Installation
 *
 * @author	Martin Hesse <info@mh-dev.de>
 * @package	MH-Dev.-Board
 */
class InstallController extends Zend_Controller_Action
{
	public function init()
	{
		// config
		$config = Zend_Registry::get('config');
		
		// init layout
		$layout = Zend_Layout::startMvc(array(
            'layoutPath' => $config->appPath . '/layouts/default'
        ));
        
        $view	= $layout->getView();
        $view->setBasePath($config->appPath . '/views/default');
		$view->addHelperPath('MHDEV/View/Helper/', 'MHDEV_View_Helper_');
		
        // disable layout
		Zend_Layout::getMvcInstance()->disableLayout();
	}
	
	
	
	/*
	 * Installation-Page
	 * 
	 * @param null
	 * 
	 * @return void
	 */
	public function indexAction()
	{
		if(!Zend_Registry::isRegistered('settings'))
		{
			// vars
			$postData 	= $this->_request->getPost();
			$error		= false;
			
			// get post
			if($this->_request->isPost())
			{
				if(strlen($postData['mail']) > 0 && strlen($postData['password']) > 0)
				{
					if($this->createDatabases())
					{
						// db
						$user = new User();
						$user->insert(array(
							'role'		=> 'admin',
							'username'	=> 'Admin',
							'mail'		=> $postData['mail'],
							'password'	=> md5($postData['password']),
							'is_active'	=> 1
						));
						
						$this->_redirect('/');
					}
				}
				else
				{
					$error = true;
				}
			}
			
			$this->view->error = $error;
		}
		else
		{
			$this->_redirect('/');
		}
	}
	
	
	
	/*
	 * Create all nessisary database tables
	 * 
	 * @param null
	 * 
	 * @return boolean
	 */
	private function createDatabases()
	{
		// db
		$db = Zend_Registry::get('db');
		
		if($db)
		{
			$db->getConnection()->exec($this->dbBENavigation());
			$db->getConnection()->exec($this->dbInsertBENavigaton());
			$db->getConnection()->exec($this->dbBan());
			$db->getConnection()->exec($this->dbBoards());
			$db->getConnection()->exec($this->dbBoardsVisited());
			$db->getConnection()->exec($this->dbCategories());
			$db->getConnection()->exec($this->dbGroups());
			$db->getConnection()->exec($this->dbInsertGroups());
			$db->getConnection()->exec($this->dbLayouts());
			$db->getConnection()->exec($this->dbInsertLayouts());
			$db->getConnection()->exec($this->dbMessages());
			$db->getConnection()->exec($this->dbNavigation());
			$db->getConnection()->exec($this->dbInsertNavigation());
			$db->getConnection()->exec($this->dbPermission());
			$db->getConnection()->exec($this->dbInsertPermission());
			$db->getConnection()->exec($this->dbPermissions());
			$db->getConnection()->exec($this->dbInsertPermissions());
			$db->getConnection()->exec($this->dbPolls());
			$db->getConnection()->exec($this->dbPollsAnswers());
			$db->getConnection()->exec($this->dbPollsVotes());
			$db->getConnection()->exec($this->dbPosts());
			$db->getConnection()->exec($this->dbRank());
			$db->getConnection()->exec($this->dbInsertRank());
			$db->getConnection()->exec($this->dbRates());
			$db->getConnection()->exec($this->dbSettings());
			$db->getConnection()->exec($this->dbInsertSettings());
			$db->getConnection()->exec($this->dbSmilies());
			$db->getConnection()->exec($this->dbInsertSmilies());
			$db->getConnection()->exec($this->dbThreads());
			$db->getConnection()->exec($this->dbThreadsVisited());
			$db->getConnection()->exec($this->dbThreadsNotice());
			$db->getConnection()->exec($this->dbTickets());
			$db->getConnection()->exec($this->dbUser());
			$db->getConnection()->exec($this->dbInsertUser());
			$db->getConnection()->exec($this->dbUserBuddies());
			$db->getConnection()->exec($this->dbUserGuestbook());
			$db->getConnection()->exec($this->dbUserOnline());
			$db->getConnection()->exec($this->dbUserOnlineCount());
			
			return true;
		}
		else
		{
			return false;
		}
	}
	
	private function dbBENavigation()
	{
		return "CREATE TABLE IF NOT EXISTS `backend_navigation` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`sort_id` int(11) NOT NULL DEFAULT '0',
		 	 `hidden` char(1) NOT NULL DEFAULT '0',
			`locked` char(1) NOT NULL DEFAULT '0',
			`title` varchar(255) NOT NULL,
			`action` varchar(255) NOT NULL DEFAULT 'index',
			`controller` varchar(255) NOT NULL DEFAULT 'index',
			`role` varchar(255) NOT NULL,
			`route` varchar(255) NOT NULL DEFAULT 'default',
			`lang_key` varchar(255) NOT NULL DEFAULT 'null',
			`is_spacer` tinyint(1) NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=18;";
	}
	
	private function dbInsertBENavigaton()
	{
		return "INSERT INTO `backend_navigation` (`uid`, `sort_id`, `hidden`, `locked`, `title`, `action`, `controller`, `role`, `route`, `lang_key`, `is_spacer`) VALUES
		(1, 1, '0', '0', 'Posts', 'index', 'posts', 'moderation,admin', 'be_posts', 'navigation_posts', 0),
		(2, 2, '0', '0', 'Threads', 'index', 'threads', 'moderation,admin', 'be_threads', 'navigation_threads', 0),
		(3, 3, '0', '0', 'Log', 'index', 'log', 'moderation,admin', 'be_log', 'navigation_log', 0),
		(4, 4, '0', '0', 'Ban', 'index', 'ban', 'moderation,admin', 'be_ban', 'navigation_ban', 0),
		(5, 5, '0', '0', 'Rank', 'index', 'rank', 'moderation,admin', 'be_rank', 'navigation_rank', 0),
		(6, 6, '0', '0', 'Smilies', 'index', 'smilies', 'moderation,admin', 'be_smilies', 'navigation_smilies', 0),
		(7, 15, '0', '0', 'Navigation', 'backend', 'navigation', 'admin', 'be_navi', 'navigation_backend', 0),
		(8, 9, '0', '0', 'Boards', 'index', 'boards', 'admin', 'be_boards', 'null', 0),
		(9, 0, '0', '0', 'Moderation', '', '', '', 'default', 'null', 1),
		(10, 6, '0', '0', 'Navigation', 'frontend', 'navigation', 'moderation,admin', 'be_navi_fe', 'null', 0),
		(11, 14, '0', '0', 'Settings', 'index', 'settings', 'admin', 'be_settings', 'null', 0),
		(12, 13, '0', '0', 'Themes', 'index', 'themes', 'admin', 'be_themes', 'null', 0),
		(13, 12, '0', '0', 'Permissions', 'index', 'permissions', 'admin', 'permissions', 'null', 0),
		(14, 11, '0', '0', 'Groups', 'index', 'groups', 'admin', 'be_groups', 'null', 0),
		(15, 10, '0', '0', 'User', 'index', 'user', 'admin', 'be_user', 'null', 0),
		(16, 8, '0', '0', 'Categories', 'index', 'categories', 'admin', 'be_categories', 'null', 0),
		(17, 7, '0', '0', 'Administration', '', '', '', 'default', 'null', 1);";
	}
	
	private function dbBan()
	{
		return "CREATE TABLE IF NOT EXISTS `ban` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`user_uid` int(11) NOT NULL,
			`admin_uid` int(11) NOT NULL,
			`thread_uid` int(11) NOT NULL DEFAULT '0',
			`board_uid` int(11) NOT NULL DEFAULT '0',
			`post_uid` int(11) NOT NULL,
			`create_date` datetime NOT NULL,
			`expire_date` date NOT NULL,
			`reason` text NOT NULL,
			`is_deleted` tinyint(1) NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
	}
	
	private function dbBoards()
	{
		return "CREATE TABLE IF NOT EXISTS `boards` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`category_uid` int(11) NOT NULL,
			`group_uid` int(11) NOT NULL,
			`root_uid` int(11) NOT NULL DEFAULT '0',
			`last_thread_uid` int(11) NOT NULL,
			`last_post_uid` int(11) NOT NULL,
			`sort_uid` int(11) NOT NULL,
			`count_threads` int(11) NOT NULL,
			`count_posts` int(11) NOT NULL,
			`allow_guests` tinyint(1) NOT NULL,
			`allow_guest_posts` tinyint(1) NOT NULL,
			`allow_guest_threads` tinyint(1) NOT NULL,
			`is_hidden` tinyint(1) NOT NULL,
			`is_public` int(11) NOT NULL DEFAULT '1',
			`is_deleted` tinyint(1) NOT NULL,
			`title` varchar(255) NOT NULL,
			`desc` text NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
	}
	
	private function dbBoardsVisited()
	{
		return "CREATE TABLE IF NOT EXISTS `boards_visited` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`user_uid` int(11) NOT NULL,
			`date` datetime NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
	}
	
	private function dbCategories()
	{
		return "CREATE TABLE IF NOT EXISTS `categories` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`title` varchar(255) NOT NULL,
			`lang_key` varchar(255) NOT NULL,
			`is_hidden` tinyint(1) NOT NULL,
			`is_deleted` tinyint(1) NOT NULL,
			`sort_uid` int(11) NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
	}
	
	private function dbGroups()
	{
		return "CREATE TABLE IF NOT EXISTS `groups` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`perm_uid` int(11) NOT NULL,
			`title` varchar(255) NOT NULL,
			`is_public` tinyint(1) NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3";
	}
	
	private function dbInsertGroups()
	{
		return "INSERT INTO `groups` (`uid`, `perm_uid`, `title`, `is_public`) VALUES (1, 0, 'User', 1), (2, 1, 'Admin', 0)";
	}
	
	private function dbLayouts()
	{
		return "CREATE TABLE IF NOT EXISTS `layouts` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`key` varchar(255) NOT NULL,
			`title` varchar(255) NOT NULL,
			`is_public` tinyint(1) NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2";
	}
	
	private function dbInsertLayouts()
	{
		return "INSERT INTO `layouts` (`uid`, `key`, `title`, `is_public`) VALUES (1, 'default', 'Default', 1)";
	}
	
	private function dbMessages()
	{
		return "CREATE TABLE IF NOT EXISTS `messages` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`user_uid` int(11) NOT NULL,
			`receiver_uid` int(11) NOT NULL,
			`create_date` datetime NOT NULL,
			`title` varchar(255) NOT NULL,
			`text` text NOT NULL,
			`is_notice` tinyint(1) NOT NULL DEFAULT '0',
			`is_read` tinyint(1) NOT NULL DEFAULT '0',
			`is_deleted` tinyint(1) NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
	}
	
	private function dbNavigation()
	{
		return "CREATE TABLE IF NOT EXISTS `navigation` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`sort_id` int(11) NOT NULL DEFAULT '0',
			`hidden` char(1) NOT NULL DEFAULT '0',
			`locked` char(1) NOT NULL DEFAULT '0',
			`title` varchar(255) NOT NULL,
			`action` varchar(255) NOT NULL DEFAULT 'index',
			`controller` varchar(255) NOT NULL DEFAULT 'index',
			`role` varchar(255) NOT NULL,
			`route` varchar(255) NOT NULL DEFAULT 'default',
			`lang_key` varchar(255) NOT NULL DEFAULT 'null',
			PRIMARY KEY (`uid`)
		) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7";
	}
	
	private function dbInsertNavigation()
	{
		return "INSERT INTO `navigation` (`uid`, `sort_id`, `hidden`, `locked`, `title`, `action`, `controller`, `role`, `route`, `lang_key`) VALUES
		(1, 0, '0', '0', 'Forum', 'index', 'index', '', 'index', 'navi_forum'),
		(2, 2, '0', '0', 'Member', 'index', 'user', '', 'default', 'navi_member'),
		(3, 80, '1', '0', 'Admin', 'index', 'admin', 'admin', 'admin', 'navi_admin'),
		(4, 99, '0', '0', 'Logout', 'logout', 'login', 'user,moderator,admin', 'logout', 'logout'),
		(5, 3, '0', '0', 'Login', 'index', 'login', 'guest', 'login', 'login'),
		(6, 4, '0', '0', 'Register', 'index', 'register', 'guest', 'register', 'register')";
	}
	
	private function dbPermission()
	{
		return "CREATE TABLE IF NOT EXISTS `permission` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`title` varchar(255) NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2";
	}
	
	private function dbInsertPermission()
	{
		return "INSERT INTO `permission` (`uid`, `title`) VALUES (1, 'Global-Moderator')";
	}
	
	private function dbPermissions()
	{
		return "CREATE TABLE IF NOT EXISTS `permissions` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`perm_uid` int(11) NOT NULL,
			`board_uid` varchar(4) NOT NULL DEFAULT '0',
			`has_access` tinyint(1) NOT NULL,
			`is_moderator` tinyint(1) NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2";
	}
	
	private function dbInsertPermissions()
	{
		return "INSERT INTO `permissions` (`uid`, `perm_uid`, `board_uid`, `has_access`, `is_moderator`) VALUES (1, 1, 'all', 1, 1)";
	}
	
	private function dbPolls()
	{
		return "CREATE TABLE IF NOT EXISTS `polls` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`question` text NOT NULL,
			`thread_uid` int(11) NOT NULL,
			`title` varchar(255) NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
	}
	
	private function dbPollsAnswers()
	{
		return "CREATE TABLE IF NOT EXISTS `polls_answers` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`poll_uid` int(11) NOT NULL,
			`title` varchar(255) NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
	}
	
	private function dbPollsVotes()
	{
		return "CREATE TABLE IF NOT EXISTS `polls_votes` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`poll_uid` int(11) NOT NULL,
			`answer_uid` int(11) NOT NULL,
			`user_uid` int(11) NOT NULL,
			`date` datetime NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
	}
	
	private function dbPosts()
	{
		return "CREATE TABLE IF NOT EXISTS `posts` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`thread_uid` int(11) NOT NULL,
			`user_uid` int(11) NOT NULL,
			`title` varchar(255) NOT NULL,
			`text` text NOT NULL,
			`ban_reason` text NOT NULL,
			`create_date` datetime NOT NULL,
			`edit_date` datetime NOT NULL,
			`count_edit` int(11) NOT NULL,
			`is_deleted` tinyint(1) NOT NULL,
			`is_public` tinyint(1) NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
	}
	
	private function dbRank()
	{
		return "CREATE TABLE IF NOT EXISTS `rank` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`title` varchar(255) NOT NULL,
			`lang_key` varchar(255) NOT NULL,
			`xp_begin` int(11) NOT NULL,
			`xp_end` int(11) NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=16";
	}
	
	private function dbInsertRank()
	{
		return "INSERT INTO `rank` (`uid`, `title`, `lang_key`, `xp_begin`, `xp_end`) VALUES
		(1, 'Rang 1', 'rank_1', 0, 6),
		(2, 'Rang 2', 'rank_2', 7, 16),
		(3, 'Rank 3', 'rank_3', 17, 35),
		(4, 'Rank 4', 'rank_4', 36, 84),
		(5, 'Rank 5', 'rank_5', 85, 202),
		(6, 'Rank 6', 'rank_6', 203, 499),
		(7, 'Rank 7', 'rank_7', 500, 1245),
		(8, 'Rank 8', 'rank_8', 1246, 3158),
		(9, 'Rank 9', 'rank_9', 3159, 8101),
		(10, 'Rank 10', 'rank_10', 8102, 20982),
		(11, 'Rank 11', 'rank_11', 20983, 54769),
		(12, 'Rank 12', 'rank_12', 54770, 143858),
		(13, 'Rank 13', 'rank_13', 143859, 379720),
		(14, 'Rank 14', 'rank_14', 379721, 1006170),
		(15, 'Rank 15', 'rank_15', 1006171, 9999999)";
	}
	
	private function dbRates()
	{
		return "CREATE TABLE IF NOT EXISTS `rates` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`post_uid` int(11) NOT NULL,
			`user_uid` int(11) NOT NULL,
			`value` char(4) NOT NULL,
			`date` datetime NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
	}
	
	private function dbSettings()
	{
		return "CREATE TABLE IF NOT EXISTS `settings` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`board_name` varchar(255) NOT NULL,
			`admin_mail` varchar(255) NOT NULL,
			`domain_name` varchar(255) NOT NULL,
			`threads_per_page` int(11) NOT NULL DEFAULT '10',
			`posts_per_page` int(11) NOT NULL DEFAULT '10',
			`default_language` varchar(3) NOT NULL DEFAULT 'en',
			`is_online` tinyint(1) NOT NULL DEFAULT '1',
			`offline_message` text NOT NULL,
			`user_auth` tinyint(1) NOT NULL DEFAULT '1',
			`allow_rating` tinyint(1) NOT NULL,
			`allow_votes` tinyint(1) NOT NULL,
			`is_installed` tinyint(1) NOT NULL,
			`avatar_upload` tinyint(1) NOT NULL,
			`avatar_size` INT( 11 ) NOT NULL,
			`avatar_height` INT( 11 ) NOT NULL DEFAULT '100',
			`avatar_width` INT( 11 ) NOT NULL DEFAULT '100',
			`online_count` INT( 5 ) NOT NULL DEFAULT '30',
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2";
	}
	
	private function dbInsertSettings()
	{
		return "INSERT INTO `settings` (`uid`, `board_name`, `admin_mail`, `domain_name`, `threads_per_page`, `posts_per_page`, `default_language`, `is_online`, `offline_message`, `user_auth`, `allow_rating`, `allow_votes`, `is_installed`) VALUES
		(1, 'MH-Dev.-Board', '', '', 10, 10, 'en', 1, '', 1, 1, 1, 1)";
	}
	
	private function dbSmilies()
	{
		return "CREATE TABLE IF NOT EXISTS `smilies` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`wrapper` varchar(255) NOT NULL,
			`desc` varchar(255) NOT NULL,
			`image` varchar(255) NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=25";
	}
	
	private function dbInsertSmilies()
	{
		return "INSERT INTO `smilies` (`uid`, `wrapper`, `desc`, `image`) VALUES
		(1, ';)', ';)', 'Blink.gif'),
		(2, ':)', '*Smile* :)', 'Smile.gif'),
		(3, ':-)', '*Smile* :)', 'Smile.gif'),
		(4, ':D', '*Big grin* :D', 'Very_Happy.gif'),
		(5, ':-D', '*Big grin* :-D', 'Very_Happy.gif'),
		(6, ':p', ':p', 'Ba!.gif'),
		(7, ':-p', ':-p', 'Ba!.gif'),
		(8, ':(', '*Sad* :(', 'Sad.gif'),
		(9, ':-(', '*Sad* :-(', 'Sad.gif'),
		(10, ':lol:', '*lol*', 'Lol.gif'),
		(11, ':ashamed:', '*Ashamed* :ashamed:', 'Ashamed.gif'),
		(12, ':shy:', '*Ashamed* :shy:', 'Ashamed.gif'),
		(13, '>D', '*Bad* >D', 'Bad.gif'),
		(14, 'oO', '*Confused* oO', 'Confused.gif'),
		(15, 'Oo', '*Confused* Oo', 'Confused.gif'),
		(16, '8-D', '*Cool* 8-D', 'Cool.gif'),
		(17, ':crazy:', '*Crazy* :crazy:', 'Crazy.gif'),
		(18, ':happy:', '*Happy* :happy:', 'Happy.gif'),
		(19, ':laugh:', '*Laughing* :laugh:', 'Laughing.gif'),
		(20, ':rolleyes:', '*Rolleyes* :rolleyes:', 'Looking_up.gif'),
		(21, ':aww:', '*Shock* :aww:', 'Shock.gif'),
		(22, ':swit:', '*Swit* :swit:', 'Swit.gif'),
		(23, ':|', ':|', 'Neutral.gif'),
		(24, ':-|', ':-|', 'Neutral.gif')";
	}
	
	private function dbThreads()
	{
		return "CREATE TABLE IF NOT EXISTS `threads` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`board_uid` int(11) NOT NULL,
			`user_uid` int(11) NOT NULL DEFAULT '0',
			`moved_uid` int(11) NOT NULL DEFAULT '0',
			`create_date` datetime NOT NULL,
			`last_reply_date` datetime NOT NULL,
			`last_reply_user_uid` int(11) NOT NULL,
			`count_replies` int(11) NOT NULL,
			`count_hits` int(11) NOT NULL,
			`title` varchar(255) NOT NULL,
			`is_moderated` tinyint(1) NOT NULL,
			`is_public` tinyint(1) NOT NULL,
			`is_closed` tinyint(1) NOT NULL,
			`is_sticky` tinyint(1) NOT NULL,
			`is_deleted` tinyint(1) NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
	}
	
	private function dbThreadsVisited()
	{
		return "CREATE TABLE IF NOT EXISTS `threads_visited` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`user_uid` int(11) NOT NULL,
			`thread_uid` int(11) NOT NULL,
			`date` datetime NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
	}
	
	private function dbThreadsNotice()
	{
		return "CREATE TABLE IF NOT EXISTS `threads_notice` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`user_uid` int(11) NOT NULL,
			`thread_uid` int(11) NOT NULL,
			`last_post` datetime NOT NULL,
			PRIMARY KEY (`uid`),
			UNIQUE KEY `uid` (`uid`)
		) ENGINE=InnoDB  DEFAULT CHARSET=latin1;";	
	}
	
	private function dbTickets()
	{
		return "CREATE TABLE IF NOT EXISTS `tickets` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`user_uid` int(11) NOT NULL,
			`thread_uid` int(11) NOT NULL,
			`post_uid` int(11) NOT NULL,
			`title` varchar(255) NOT NULL,
			`text` text NOT NULL,
			`create_date` datetime NOT NULL,
			`is_solved` tinyint(1) NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
	}
	
	private function dbUser()
	{
		return "CREATE TABLE IF NOT EXISTS `user` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`group_uid` int(11) NOT NULL,
			`rank_uid` int(11) NOT NULL,
			`is_active` tinyint(1) NOT NULL,
			`is_online` tinyint(1) NOT NULL,
			`is_valid` tinyint(1) NOT NULL DEFAULT '0',
			`activation_code` varchar(255) NOT NULL,
			`create_date` datetime NOT NULL,
			`role` varchar(255) NOT NULL,
			`language` varchar(2) NOT NULL DEFAULT 'en',
			`count_threads` int(11) NOT NULL,
			`count_posts` int(11) NOT NULL,
			`count_unread_messages` int(11) NOT NULL,
			`count_hits` INT( 11 ) NOT NULL DEFAULT '0',
			`threads_per_page` int(4) NOT NULL DEFAULT '10',
			`posts_per_page` int(4) NOT NULL DEFAULT '10',
			`posts_rating` INT(11) NOT NULL DEFAULT '5',
			`username` varchar(255) NOT NULL,
			`forename` varchar(255) NOT NULL,
			`lastname` varchar(255) NOT NULL,
			`city` varchar(255) NOT NULL,
			`zip` int(5) NOT NULL,
			`date_of_birth` char(10) NOT NULL,
			`homepage` varchar(255) NOT NULL,
			`mail` varchar(255) NOT NULL,
			`password` varchar(255) NOT NULL,
			`signature` text NOT NULL,
			`layout` varchar(255) NOT NULL DEFAULT 'default',
			`activity_points` int(11) NOT NULL,
			`gravatar_active` tinyint(1) NOT NULL,
			`gravatar_mail` varchar(255) NOT NULL,
			`gravatar_rating` varchar(255) NOT NULL DEFAULT 'g',
			`gravatar_size` int(11) NOT NULL DEFAULT '40',
			`hash1` varchar(255) NOT NULL,
			`hash2` varchar(255) NOT NULL,
			`bad_logins` int(11) NOT NULL DEFAULT '0',
			`bad_login_date` int(11) NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
	}
	
	private function dbInsertUser()
	{
		return "INSERT INTO `user` (`uid`, `group_uid`, `rank_uid`, `is_active`, `is_online`, `is_valid`, `activation_code`, `create_date`, `role`, `language`, `count_threads`, `count_posts`, `count_unread_messages`, `threads_per_page`, `posts_per_page`, `username`, `forename`, `lastname`, `city`, `zip`, `date_of_birth`, `homepage`, `mail`, `password`, `signature`, `layout`, `activity_points`) VALUES
		(0, 0, 0, 1, 0, 0, '', '2009-07-25 00:00:00', 'guest', 'en', 0, 0, 0, 10, 0, 'Guest/Gast', '', '', '', 0, '', '', '', 'a0298767f9a29bf3aa0ba9120b254d40', '', 'default', 0)";
	}
	
	private function dbUserBuddies()
	{
		return "CREATE TABLE IF NOT EXISTS `user_buddies` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`user_uid` int(11) NOT NULL,
			`buddy_uid` int(11) NOT NULL,
			`date` datetime NOT NULL,
			`accepted` tinyint(1) NOT NULL,
			PRIMARY KEY (`uid`),
			KEY `user_uid` (`user_uid`)
		) ENGINE=MyISAM  DEFAULT CHARSET=latin1;";
	}
	
	private function dbUserGuestbook()
	{
		return "CREATE TABLE IF NOT EXISTS `user_guestbook` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`is_deleted` tinyint(1) NOT NULL,
			`guestbook_uid` int(11) NOT NULL,
			`user_uid` int(11) NOT NULL,
			`text` text NOT NULL,
			`date` datetime NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB  DEFAULT CHARSET=latin1;";
	}
	
	private function dbUserOnline()
	{
		return "CREATE TABLE IF NOT EXISTS `user_online` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`user_uid` int(11) NOT NULL,
			`board_uid` int(11) NOT NULL,
			`thread_uid` int(11) NOT NULL,
			`module` varchar(255) NOT NULL DEFAULT 'default',
			`controller` varchar(255) NOT NULL,
			`ip_address` varchar(15) NOT NULL,
			`date` datetime NOT NULL,
			PRIMARY KEY (`uid`),
			KEY `ip_address` (`ip_address`)
		) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
	}
	
	private function dbUserOnlineCount()
	{
		return "CREATE TABLE IF NOT EXISTS `user_online_count` (
			`uid` int(11) NOT NULL AUTO_INCREMENT,
			`ip_address` varchar(15) NOT NULL,
			`host_address` varchar(255) NOT NULL,
			`referer` varchar(255) NOT NULL,
			`language` varchar(255) NOT NULL,
			`resolution` varchar(255) NOT NULL,
			`browser` varchar(255) NOT NULL,
			`page` varchar(255) NOT NULL,
			`date` datetime NOT NULL,
			PRIMARY KEY (`uid`)
		) ENGINE=InnoDB  DEFAULT CHARSET=latin1;";
	}
}